local mysql = mysql or require"mysql"

db=function()
return{
        connect=function(self,db,u,p,host,port)
          local host = host or "localhost"
          local port = port
          self.__env = assert(luasql.mysql())
          self.__con = assert(self.__env:connect(db,u,p,host,port))
        end,
        query=function(self,q)
          local cur = self.__con:execute(q)
          local res = {}
          local i,j = cur:numrows(),1
          while i>=j do
            res[j]={assert(cur:fetch("a"))}
            j = j+1
          end
          cur:close()
          return res
        end,
        commit=function(self,q,data)
        
        end,
        disconnect=function(self)
            self.__env:close()
            self.__con:close()
        end,
    }
end
